# -*- coding: utf-8 -*-

import re
import redis
import json

class ScrapytestPipeline(object):
    def process_item(self, item, spider):
        return item


class FlaskDocPipeline(object):
    def process_item(self, item, spider):
    # TODO: 将 item 结果以 JSON 形式保存到 Redis 数据库的 list 结构中
        data = {'url':item['url'],'text':item['text']}
        self.redis.lpush('flask_doc:items',data)
        return item


    def open_spider(self, spider):
        # 连接数据库
        self.redis = redis.StrictRedis(host='localhost', port=6379, db=0)